<template>
  <div>
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item', item.id === 0 ? 'mui-active' : '']"
            data-wid="tab-top-subpage-1.html"
            v-for="item in photoTypes"
            :key="item.id"
            @click="getPhoto(item.id)"
          >
            {{ item.type_name }}
          </a>
        </div>
      </div>
    </div>
    <ul class="photo-list">
      <router-link v-for="item in photosInfo" :key="item.img_url" :to="'/home/photoinfo/'+item.type_id" tag="li">
        <img v-lazy="item.img_url" />
        <div class="info">
          <h3 class="info-title">{{item.title }}</h3>
          <div class="info-body">{{ item.abstract_name}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
// 解决滑动，引入mui.js
import mui from "../../lib/mui/js/mui.min.js";
//aller', 'callee', and 'arguments' properties may not be accessed on s
//trict mode functions or the arguments objects for calls to them 错误
// 解决，去掉webpack的严格模式
export default {
  data() {
    return {
      photoTypes: [],
      photosInfo: []
    };
  },
  created() {
    this.getPhotoType();
    this.getPhoto(0);
  },
  mounted() {
    // 在这块引入滑动，是为了解决第一次进入不能滑动
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    getPhotoType() {
      this.$http.get("getPhotoType").then(res => {
        if (res.status === 200) {
          res.body.unshift({
            id: 0,
            type_name: "全部"
          });
          this.photoTypes = res.body;
        }
      });
    },
    getPhoto(typeId) {
      this.$http.get("getPhotoByTypeid?id=" + typeId).then(res => {
        if (res.status === 200) {
          this.photosInfo = res.body;
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
* {
  touch-action: pan-y;
}
.photo-list {
  list-style: none;
  margin: 0;
  padding: 10px;
  padding-bottom: 0;
  li {
    background-color: #ccc;
    text-align: center;
    margin-bottom: 10px;
    box-shadow: 0 0 9px #999;
    position: relative;
    img{
      width: 100%;
      vertical-align: middle;
      
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
    .info{
      text-align: left;
      color: white;
      background-color: rgba(0,0,0,0.4);
      max-height: 84px;
      position: absolute;
      bottom: 0;
      .info-title{
        font-size: 14px;
      }
      .info-body{
        font-size: 13px;
      }
    }
  }
}
</style>
